import { createRouter, createWebHistory } from 'vue-router'
import { baseUrl } from '../config/config';
import {
  message
} from 'ant-design-vue';

const index = () =>import('pages/index')
const login = () =>import('pages/login')
const user = () =>import('pages/user')
const diseaseType = () =>import('pages/diseaseType/diseaseType')
const disease = () =>import('pages/disease/disease')
const artical = () =>import('pages/artical/artical')
const video = () =>import('pages/video/video')
const live = () =>import('pages/live/live')

const post = () =>import('pages/post')
const order = () =>import('pages/order')
const rank = () =>import('pages/rank')
const comment = () =>import('pages/comment')
const userPost = () =>import('pages/userPost')
const userOrder = () =>import('pages/userPost')

const routes = [
  {
    path: '',
    redirect: '/index'
  }, 
  {
    path:'/login',
    component:login,
  },
  {
    path:'/index',
    component:index,
    redirect:'/user',
    children:[
      {
        path:'/user',
        component:user
      },
      {
        path:'/diseaseType',
        component:diseaseType
      },
      {
        path:'/disease',
        component:disease
      },
      {
        path:'/artical',
        component:artical
      },
      {
        path:'/live',
        component:live
      },
      {
        path:'/video',
        component:video
      },
      {
        path:'/post',
        component:post
      },
      {
        path:'/order',
        component:order
      },
      {
        path:'/rank',
        component:rank
      },
      {
        path:'/comment',
        component:comment
      },
      {
        path:'/userPost',
        component:userPost
      },
      {
        path:'/userOrder',
        component:userOrder
      },
    ]
  },
  
]

const router = createRouter({
  history: createWebHistory(baseUrl),
  routes
})

//守挂载路由导航卫
// router.beforeEach((to,from,next) => {
//   if(to.path === '/login') return next();
//   //获取token
//   const tokenStr = window.sessionStorage.getItem('token')
//   if(!tokenStr) return next('/login')
//   next()
// })

export default router
